import { watch, ref } from 'vue';

export function useWatchLater() {
  const watchVarStop = ref(null);

  function watchLater(watchVal, watchFn, option) {
    if (watchVarStop.value && typeof watchVarStop.value === 'function') {
      watchVarStop.value();
    }

    watchVarStop.value = watch(
      watchVal,
      watchFn,
      option
    );
  }

  return watchLater;
}
